package com.carkeeper.storebill.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class RabbitConfig {

    public static final String STORE_BILL_PAY="store_bill_pay";
    public static final String EX_STORE_BILL_PAY="ex_store_bill_pay";

    /**
     * 配置账单支付交换机
     * @return
     */
    @Bean("exStoreBillPay")
    public Exchange exStoreBillPay(){

        return ExchangeBuilder.fanoutExchange(EX_STORE_BILL_PAY).build();
    }


    /**
     * 添加账单支付队列
     * @return
     */
    @Bean("storeBillPay")
    public Queue storeBillPay(){
        return new Queue(STORE_BILL_PAY);
    }

    /**
     * 绑定支付账单队列到交换机
     * @param queue
     * @param exchange
     * @return
     */
    @Bean
    public Binding BindingQueueaddpoint (@Qualifier("storeBillPay")Queue queue, @Qualifier("exStoreBillPay")Exchange exchange){

        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }
}
